﻿//
// Copyright 2008-2011 by Burt Harris
// Licensed under the Microsoft Public License (Ms-PL)
// See: http://www.codeplex.com/yaml/license
//

using System;
using System.Diagnostics.Contracts;
using System.Runtime.Serialization;
using Microsoft.Scripting;

namespace YaTools.Yaml
{
    [Serializable]
    public class YamlSyntaxErrorException : SyntaxErrorException
    {
        // Methods
        public YamlSyntaxErrorException()
        {
        }

        public YamlSyntaxErrorException(string message)
            : base(message)
        {
        }

        protected YamlSyntaxErrorException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            Contract.Requires(info != null);
        }

        public YamlSyntaxErrorException(string message, Exception innerException)
            : base(message, innerException)
        {
        }

        public YamlSyntaxErrorException(string message, string path, string code, string line, SourceSpan span,
                                        int errorCode, Severity severity)
            : base(message, path, code, line, span, errorCode, severity)
        {
            Contract.Requires(message != null);
        }

        public override string ToString()
        {
            return string.Format("YAML syntax error: {0}", Message);
        }

        public override bool Equals(object obj)
        {
            var other = obj as YamlSyntaxErrorException;
            if (other == null) return false;
            return (ErrorCode == other.ErrorCode);
        }

        public override int GetHashCode()
        {
            return ErrorCode;
        }
    }
}